package com.lifa.controller;

import com.lifa.dao.DianpuDao;
import com.lifa.entity.Dianpu;
import com.lifa.entity.Kucun;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/dianpu")
@Scope("prototype")
public class DianpuConrtoller {
    @Autowired
    public DianpuDao dianpuDao;

    @RequestMapping("/Dianpu1")
    @ResponseBody
    public List<Dianpu> Dianpu1(){

        return dianpuDao.selectDianpu();
    }

    @RequestMapping("/dianpufenye1")
    @ResponseBody
    public Map<String,Object> dianpufenye1( int offset, int limit){
        Map<String,Object> map=new HashMap<>();
        map.put("rows",dianpuDao.Dianpufenye(offset,limit));
        map.put("total",dianpuDao.Dianpuzongtiaoshu());
        return map;
    }

    /**
     * 绑定下拉框
     * @return
     */
    @RequestMapping("/chax")
    @ResponseBody
    public List<Dianpu>  chax(){
        return dianpuDao.chax();
    }
    /**
     * 删除
     * @param dianpu_Id
     * @return
     */
    @RequestMapping("/delete1")
    @ResponseBody
    public long deleteDianpu(int dianpu_Id){
        return dianpuDao.DeleteDianpu(dianpu_Id);
    }

    /**
     * 添加
     * @param dianpu_Name
     * @return
     */
    @RequestMapping("/insert1")
    @ResponseBody
    public long InsertDinapu(String dianpu_Name){
        return dianpuDao.InsertDinapu(dianpu_Name);
    }
    @RequestMapping("/queryId")
    @ResponseBody
    public Dianpu queryId(int dianpu_Id){
        return dianpuDao.queryId(dianpu_Id);
    }

    @RequestMapping("/update1")
    @ResponseBody
    public int UpdateDianpu(Dianpu dianpu){
        return dianpuDao.UpdateDianpu(dianpu);
    }

}
